﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Cms.Model;
using Portal.Database.Service;
using Portal.Web.Utility;
using Portal.Core;

namespace Portal.Cms.Bussiness
{
    public class ContactUsProcessBll
    {
        public static ContactUsCls CreateContactUsModel(string SiteId, string ContactUsId)
        {
            IDatabaseService DBService = WebDatabaseService.CreateDBService(SiteId);
            DataSet dsResult =
                    DBService.GetDataSet(null, "select * from TableContactUs where ContactUsId=@ContactUsId ",
                    new DbParam[] 
                    { 
                        new DbParam("ContactUsId", ContactUsId),
                    });
            if (dsResult.Tables[0].Rows.Count == 0)
            {
                return null;
            }
            ContactUsCls OContactUs = ContactUsParser.ParseFromDataRow(dsResult.Tables[0].Rows[0]);
            dsResult.Clear();
            dsResult.Dispose();
            return OContactUs;
        }

     


        public static ContactUsCls[] ReadingContactUs(string SiteId)
        {
            IDatabaseService DBService = WebDatabaseService.CreateDBService(SiteId);
            SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
            string AssetCode = WebSessionUtility.GetCurrentLoginUser().AssetCode;
            string DataLanguage = WebConfig.GetDataLanguage(OSiteParam);
            
            DataSet dsResult =
                    DBService.GetDataSet(null, "select * from TableContactUs " +
                                               "     where AssetCode=@AssetCode and DataLanguage=@DataLanguage order by EntryDate DESC",
                    new DbParam[] 
                    { 
                        new DbParam("AssetCode", AssetCode),
                        new DbParam("DataLanguage", DataLanguage),
                    });
            if (dsResult.Tables[0].Rows.Count == 0)
            {
                return new ContactUsCls[0];
            }
            ContactUsCls[] ContactUs = ContactUsParser.ParseFromDataTable(dsResult.Tables[0]);
            dsResult.Clear();
            dsResult.Dispose();
            return ContactUs;
        }


        public static void DeleteContactUs(string SiteId, string ContactUsId)
        {
            IDatabaseService DBService = WebDatabaseService.CreateDBService(SiteId);
            string Query =
                " Delete from TableContactUs where ContactUsId=@ContactUsId; ";
            DBService.ExecuteNonQuery(null, Query,
                    new DbParam[] 
                    { 
                        new DbParam("ContactUsId", ContactUsId),
                    });
        }

    }
}

